import * as echarts from '../../../ec-canvas/echarts';

let chart = null;

function initChart1(canvas, width, height) {
  const chart = echarts.init(canvas, null, {
    width: width,
    height: height
  });
  canvas.setChart(chart);
  var option = {
    xAxis: {
      type: 'category',
      data: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12'],
      name: '月份',
      nameLocation: 'end'
    },
    yAxis: {
      type: 'value',
      name: '人数',
      nameLocation: 'end'
    },
    series: [{
      data: [100, 400, 4000, 6500, 7800, 6500, 4500, 3000, 5200, 3000, 5200, 3000],
      type: 'bar',
      itemStyle: {
         color: '#00C89F'
      },  
      barWidth: '60%'
    }]
  };
  chart.setOption(option);
  return chart;
}
function initChart2(canvas, width, height) {
  const chart = echarts.init(canvas, null, {
    width: width,
    height: height
  });
  canvas.setChart(chart);
  var option = {
    xAxis: {
      type: 'category',
      data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
    },
    yAxis: {
      type: 'value'
    },
    series: [{
      data: [20, 32, 1, 34, 290, 330, 320],
      type: 'line'
    }]
  };
  chart.setOption(option);
  return chart;
} 
function initChart3(canvas, width, height) {
  const chart = echarts.init(canvas, null, {
    width: width,
    height: height
  });
  canvas.setChart(chart);
  var option = {
    xAxis: {
      type: 'category',
      data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
    },
    yAxis: {
      type: 'value'
    },
    series: [{
      data: [20, 32, 1, 34, 90, 30, 20],
      type: 'line',
      itemStyle: {
        normal: {
          lineStyle: {
            color: '#0000ff'
          }
        }
      },  
    }]
  };
  chart.setOption(option);
  return chart;
}
function initChart4(canvas, width, height) {
  const chart = echarts.init(canvas, null, {
    width: width,
    height: height
  });
  canvas.setChart(chart);
  var option = {
    xAxis: {
      type: 'category',
      data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
    },
    yAxis: {
      type: 'value'
    },
    series: [{
      data: [10, 42, 21, 34, 70, 50, 20],
      type: 'line',
      itemStyle: {
        normal: {
          lineStyle: {
            color: 'orange'
          }
        }
      },  
    }]
  };
  chart.setOption(option);
  return chart;
}
Page({
  /**
   * 页面的初始数据
   */
  data: {
    type: 1, //1-加盟数 2-总利润 3-平均收入
    products:[
      { img: '/images/book_01.png'},
      { img: '/images/book_02.png' },
      { img: '/images/book_01.png' },
    ],
    newsList:[
      { id: '1', 
        text: '养老金2035年或将耗尽结余 7后80后90后的养老问题该何去何从',
        date: '2019-07-09'  
      },
      { id: '2', text: '为什么这个小国的科技能横行中东，屹立于世界强国之林？',
        date: '2019-07-09'
      },
      { id: '3', text: '李嘉诚背后的一张王牌：它一年营收1441亿，全球门店数超1.2万家',
        date: '2019-07-09'
      },
      { id: '4', text: '他曾跟格力抢成龙，而今公司90%市值蒸发，82亿成泡沫靠卖地求生',
        date: '2019-07-09'
      },
      {
        id: '5', text: '华为宣布维修服务延长，包含88款机型，再也不怕屏幕碎了',
        date: '2019-07-09'
      }
    ],
    ec1: {
      onInit: initChart1
    },
    ec2: {
      onInit: initChart2
    },
    ec3: {
      onInit: initChart3
    },
    ec4: {
      onInit: initChart4
    },
    list:[
      { title: '自动化设备', time: '00:05', img:'http://117.50.74.54:8082/image/showImage?imageName=wechat/icon_index_1.png'},
      { title: '医疗器械', time: '00:05', img: 'http://117.50.74.54:8082/image/showImage?imageName=wechat/icon_index_2.png' },
      { title: '自动化设备', time: '00:05', img: 'http://117.50.74.54:8082/image/showImage?imageName=wechat/icon_index_3.png' },
      { title: '美容器械', time: '00:05', img: 'http://117.50.74.54:8082/image/showImage?imageName=wechat/icon_index_4.png' }
    ]
  },
  tabsClick:function(event){
    //console.log(event);
    this.setData({
      type: event.currentTarget.dataset.gid
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})